package cn.com.nes.site.entity.em;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据类型
 * SIGNED
 * UNSIGNED
 * ASCII
 * BINARY
 * HEX
 * UNSIGNED_LONG_AB_CD
 * UNSIGNED_LONG_CD_AB
 * SIGNED_LONG_AB_CD
 * SIGNED_LONG_CD_AB
 * FLOAT_AB_CD
 * FLOAT_CD_AB
 */
public enum DataType implements ExcelEnum {
    SIGNED(0, "16位有符号整型", 16, 0, 0, 0, 0),
    UNSIGNED(1, "16位无符号整型", 16, 0, 0, 1, 0),
    ASCII(2, "ASCII", 8, 13, 10, 1, 0),
    BINARY(3, "二进制", 1, 1, 1, 1, 0),
    HEX(4, "十六进制", 16, 12, 6, 1, 0),
    UNSIGNED_LONG_AB_CD(5, "32位无符号长整型 AB CD", 32, 0, 0, 1, 0),
    UNSIGNED_LONG_CD_AB(6, "32位无符号长整型 CD AB", 32, 0, 0, 1, 1),
    SIGNED_LONG_AB_CD(7, "32位有符号长整型 AB CD", 32, 0, 0, 0, 0),
    SIGNED_LONG_CD_AB(8, "32位有符号长整型 CD AB", 32, 0, 0, 0, 1),
    FLOAT_AB_CD(9, "32位浮点型 AB CD", 32, 8, 7, 0, 0),
    FLOAT_CD_AB(10, "32位浮点型 CD AB", 32, 8, 7, 0, 1),
    ASCII_16(11, "ASCII_16", 16, 13, 10, 1, 0),
    ASCII_32(12, "ASCII_32", 32, 13, 10, 1, 0),
    CUSTOM(13, "自定义8位", 8, 11, 0, 1, 0),
    CUSTOM_16(14, "自定义16位", 16, 11, 0, 1, 0),
    CUSTOM_32(15, "自定义32位", 32, 11, 0, 1, 0),
    CUSTOM_64(16, "自定义64位", 64, 11, 0, 1, 0),
    ;


    private static final Map<Integer, DataType> map;

    static {
        map = new HashMap<>();
        for (DataType dataType : DataType.values()) {
            map.put(dataType.getIndex(), dataType);
        }
    }

    private final int index;
    private final String name;

    private final Integer length;

    private final Integer convertId;

    private final Integer controlConvertId;

    private final Integer unsigned;

    private final Integer endian;

    DataType(int index, String name, Integer length, Integer convertId, Integer controlConvertId, Integer unsigned, Integer endian) {
        this.index = index;
        this.name = name;
        this.length = length;
        this.convertId = convertId;
        this.controlConvertId = controlConvertId;
        this.unsigned = unsigned;
        this.endian = endian;
    }

    public static DataType getDataType(int index) {
        return map.get(index);
    }

    public int getIndex() {
        return index;
    }

    public String getName() {
        return name;
    }

    public Integer getLength() {
        return length;
    }

    public Integer getConvertId() {
        return convertId;
    }

    public Integer getUnsigned() {
        return unsigned;
    }

    public Integer getEndian() {
        return endian;
    }

    public Integer getControlConvertId() {
        return controlConvertId;
    }

    @Override
    public String cellName() {
        return this.name;
    }

}
